Skip to main content

LightGBM With Cuda

Ubuntu Setup Instructions

  1. Install cmake sudo apt install cmake

  2. Install gcc 11.1.0:

     sudo apt update
    sudo apt install build-essential wget libgmp-dev libmpfr-dev libmpc-dev flex bison

    wget https://ftp.gnu.org/gnu/gcc/gcc-11.1.0/gcc-11.1.0.tar.gz
    tar -xvf gcc-11.1.0.tar.gz
    cd gcc-11.1.0

    ./contrib/download_prerequisites

    mkdir build
    cd build

    ../configure --prefix=/opt/gcc-11.1.0 --enable-languages=c,c++ --disable-multilib

    # This next step took ~10 minutes:
    make -j$(nproc)
    sudo make install
  3. Configure gcc with update-alternatives to easily switch versions:

     sudo update-alternatives --install /usr/bin/gcc gcc /opt/gcc-11.1.0/bin/gcc 50
    sudo update-alternatives --install /usr/bin/g++ g++ /opt/gcc-11.1.0/bin/g++ 50
  4. Switch to the 11.1.0 version:

     sudo update-alternatives --config gcc
    1
    sudo update-alternatives --config g++
    1
  5. Install LightGBM with Cuda support:

     # Create or activate virtualenv:
    workon gqc-utility-notebooks

    # Download and install LightGBM:
    cd ~/Downloads/
    git clone --recursive https://github.com/microsoft/LightGBM
    cd LightGBM
    rm -rf ./build
    mkdir build
    cd build
    cmake -DUSE_CUDA=1 ..
    # NOTE: -j16 means use 16 cores. Change this based on number of cores available.
    make -j16
    cd ..
    sh ./build-python.sh install --precompile --gpu
  6. Switch back to the default version of gcc:

     sudo update-alternatives --config gcc
    0
    sudo update-alternatives --config g++
    0

Issues Faced

  • Ubuntu didn't come preinstalled with cmake.
  • The newer version of gcc (11.4.0) can't compile LightGBM (semi-known issue), so we had to install an older version (11.1.0).
  • Need to make sure "cuda" is the device specified, NOT GPU!